<?php

namespace mybackend\controllers;

use common\repositories\myhtsq\ContractManageRepository;
use common\repositories\myhtsq\InvoiceReceivableRepository;
use common\repositories\myhtsq\InvoiceRepository;
use common\services\myhtsq\ContractReceivableService;
use common\services\myhtsq\ContractService;
use common\services\myhtsq\ErpInterfaceService;
use common\services\myhtsq\InvoiceService;
use common\models\myhtsq\InvoiceModel;

use common\services\myhtsq\SpecialApprovalAuthorizeService;
use Yii;

class ChannelController extends BaseController
{
    protected $_contractService;
    protected $_erpInterfaceService;
    protected $_receivableService;
    private $_invoiceService;
    protected $_authorizeService;
    private $_key = "reyyu7^uujw$@!&*h@123&";

    public function __construct($id, $module, ContractReceivableService $receivableService,
       ErpInterfaceService $erpInterfaceService, ContractService $contractService, InvoiceService $invoiceService,SpecialApprovalAuthorizeService $authorizeService, $config = [])
    {
        $this->_contractService = $contractService;
        $this->_erpInterfaceService = $erpInterfaceService;
        $this->_receivableService = $receivableService;
        $this->_invoiceService = $invoiceService;
        $this->_authorizeService = $authorizeService;
        parent::__construct($id, $module, $config);
    }

    public function beforeAction($action)
    {
//        $now = $this->getParamData('now');
//        $section = $this->getParamData('section');
//        if (abs($now - time()) > 86400) {
//            $this->exportJson([], 1, "已过期！");
//            exit;
//        }
//        if (empty($now) || empty($section)) {
//            $this->exportJson([], 2, "参数错误！");
//            exit;
//        }
//
//        if (substr(md5($this->_key . $now), '2', '20') != $section) {
//            $this->exportJson([], 3, "非法操作！");
//            exit;
//        }

        return true;
    }

    public function actionUpdateContractReceivable()
    {
        $receivable_id = $this->getParamData('receivable_id');
        $receivable_date = $this->getParamData('receivable_date');
        $payee_id = $this->getParamData('payee_id');

        if (empty($receivable_id)) {
            $this->exportJson([], 2, "receivable_id参数错误！");
        }

        $this->_receivableService->updateContractReceivable($receivable_id, $receivable_date, $payee_id);

        $this->exportJson([], $this->_receivableService->getErrCode(), $this->_contractService->getErrMsg());
    }

    public function actionGetContractList()
    {
        $code = $this->getParamData('code');

        if (empty($code)) {
            $this->exportJson([], 2, "code参数错误！");
        }

        $list = $this->_contractService->getContractApplicationList($code);

        $this->exportJson($list, $this->_contractService->getErrCode(), $this->_contractService->getErrMsg());
    }

    public function actionUpdateContractProductRent()
    {
        $contract = $this->getParamData('contract');
        Yii::info($contract,'push_from_rent');
        if (empty($contract)) {
            $this->exportJson([], 2, "code参数错误！");
        }
        $contract = json_decode($contract);

        $this->_contractService->updateContractApplicationRent($contract);
        $this->exportJson([], $this->_contractService->getErrCode(), $this->_contractService->getErrMsg());
    }

    public function actionSetContractTenantRelation(){
        $relationinfo = $this->getParamData('tenant');
        $relationinfo = json_decode($relationinfo);
        if (empty($relationinfo->contract_code)) {
            $this->exportJson([], 2, "合同code参数错误！");
        }
        if (empty($relationinfo->tenant_id)) {
            $this->exportJson([], 2, "租户ID参数错误！");
        }

        $this->_contractService->SetContractTenantRelation($relationinfo);
        $this->exportJson([], $this->_contractService->getErrCode(), $this->_contractService->getErrMsg());
    }

    public function actionGetContractListByCustomerId()
    {
        $customer_id = $this->getParamData('customer_id');
        if (empty($customer_id)) {
            $data = [];
        } else {
            $data = ContractManageRepository::getContractListByCustomerId($customer_id);
        }

        $this->exportJson($data, $this->_erpInterfaceService->getErrCode(), $this->_erpInterfaceService->getErrMsg());
    }

    public function actionGetCodeListByContractCode(){
        $keyword = $this->getParamData('keyword');
        if(empty($keyword)){
            $data = [];
        }else{
            $data = ContractManageRepository::getContractListByContractCode($keyword);
        }
        $this->exportJson($data, $this->_contractService->getErrCode(), $this->_contractService->getErrMsg());
    }

    public function actionGetContractByContractCode()
    {
        $contractcode = $this->getParamData('contractcode');
        if (empty($contractcode)) {
            $data = [];
        } else {
            $data = ContractManageRepository::getContractByContractCode($contractcode);
        }

        $this->exportJson($data, $this->_erpInterfaceService->getErrCode(), $this->_erpInterfaceService->getErrMsg());
    }

    private function setCustomerInfo($data)
    {
        $result = [];
        foreach ($data as $customer) {
            $customer_id = $customer['CSTGUID'];
            $customer_name = $customer['CstName'];
            $customer_full_name = $customer['CstFullName'];
            $result[] = ['customer_id' => $customer_id, 'customer_name' => $customer_name, 'customer_full_name' => $customer_full_name];
        }

        return $result;
    }

    /**
     * 获取商家系统客户信息
     */
    public function actionGetCustomerInfo()
    {
        $keyword = $this->getParamData('keyword');
        if (empty($keyword)) {//是否传值为空
            $data = [];
        } else {
            $data = $this->_erpInterfaceService->postERPCustomerApi($keyword);
        }

        $this->exportJson($this->setCustomerInfo($data), $this->_erpInterfaceService->getErrCode(), $this->_erpInterfaceService->getErrMsg());
    }

    /**
     * 合同数据接口
     */
    public function actionGetContractInfo()
    {
        $contractid = $this->getParamData('contractid');
        $beginTime = $this->getParamData('beginTime');
        $endTime = $this->getParamData('endTime');
        $data = $this->_contractService->getContractListByTime($beginTime, $endTime,$contractid);
        $data = $this->setContractRent($data);
        $this->exportJson($data, $this->_contractService->getErrCode(), $this->_contractService->getErrMsg());
    }

    /**
     * 合同返款数据接口
     */
    public function actionGetContractFk()
    {
        $contractid = $this->getParamData('contractid');
        $data = $this->_contractService->getContractFkList($contractid);

        $this->exportJson($data, $this->_contractService->getErrCode(), $this->_contractService->getErrMsg());
    }

    /**
     * 合同数据接口
     */
    public function actionGetContractInfoNoAsFields()
    {
        $beginTime = $this->getParamData('beginTime');
        $endTime = $this->getParamData('endTime');
        $data = $this->_contractService->getContractListByTimeNoAsFields($beginTime, $endTime);
        $data = $this->setContractBillPaymentAmount($data);
        $data = $this->setContractRent($data);
        $this->exportJson($data, $this->_contractService->getErrCode(), $this->_contractService->getErrMsg());
    }

    private function setContractBillPaymentAmount($contract_list, $key = 'ContractGUID')
    {
        $result = [];
        foreach ($contract_list as $contract) {
            $contract_id = $contract[$key];
            $billingAmount = $paymentAmount = 0;
            if (!empty($contract_id)) {
                $receivables = $this->_contractService->getReceivableInfoByContractId($contract_id);
                if (isset($receivables) && count($receivables) > 0) {
                    foreach ($receivables as $k => $v) {
                        $billingAmount += floatval($v['billing_amount']);
                        $paymentAmount += floatval($v['received_amount']);
                    }
                }
            }

            $contract['BillAmount'] = $billingAmount;
            $contract['PaymentAmount'] = $paymentAmount;
            $result[] = $contract;
        }

        return $result;
    }

    private function setContractRent($contract_list, $key = 'ContractGUID')
    {
        $result = [];
        foreach ($contract_list as $contract) {
            $contract_id = $contract[$key];
            $temp_begin_time = '';
            $temp_end_time = '';
            if (!empty($contract_id)) {
                $application_list = $this->_contractService->getAllContractApplicationByContractId($contract_id);
                if (!empty($application_list)) {
                    foreach ($application_list as $application) {
                        $begin_time = $application['begin_time'];
                        $end_time = $application['end_time'];
                        if (!empty($begin_time) && !empty($end_time)) {
                            if (empty($temp_begin_time)) {
                                $temp_begin_time = $begin_time;
                                $temp_end_time = $end_time;
                            } else {
                                if (strtotime($begin_time) < strtotime($temp_begin_time)) {
                                    $temp_begin_time = $begin_time;
                                    $temp_end_time = $end_time;
                                }
                            }
                        }
                    }
                }
            }

            $contract['RentBeginDate'] = $temp_begin_time;
            $contract['RentEndDate'] = $temp_end_time;
            $result[] = $contract;
        }

        return $result;
    }

    /**
     * 签约业绩接口
     */
    public function actionGetSignAchievements()
    {
        $beginTime = $this->getParamData('beginTime');
        $endTime = $this->getParamData('endTime');

        $data = $this->_contractService->getSignAchievementsByTime($beginTime, $endTime);
        $this->exportJson($data, $this->_contractService->getErrCode(), $this->_contractService->getErrMsg());
    }

    /**
     * 回款信息接口
     */
    public function actionGetPaymentInfo()
    {
        $contractid = $this->getParamData('contractid');
        $beginTime = $this->getParamData('beginTime');
        $endTime = $this->getParamData('endTime');

        $data = $this->_contractService->getPaymentInfoByTime($beginTime, $endTime,$contractid);
        $this->exportJson($data, $this->_contractService->getErrCode(), $this->_contractService->getErrMsg());
    }

    /**
     * 产品信息
     */
    public function actionGetProductInfo()
    {
        $contractid = $this->getParamData('contractid');
        $beginTime = $this->getParamData('beginTime');
        $endTime = $this->getParamData('endTime');

        $data = $this->_contractService->getProductInfoByTime($beginTime, $endTime,$contractid);
        $this->exportJson($data, $this->_contractService->getErrCode(), $this->_contractService->getErrMsg());
    }

    /**
     * 发票信息
     */
    public function actionGetInvoices()
    {
        $contractid = $this->getParamData('contractid');
        $beginTime = $this->getParamData('beginTime');
        $endTime = $this->getParamData('endTime');

        $data = $this->_contractService->getInvoicesByTime($beginTime, $endTime,$contractid);
        $this->exportJson($data, $this->_contractService->getErrCode(), $this->_contractService->getErrMsg());
    }

    /**
     * 发票摘要信息
     */
    public function actionGetInvoicesAbstract(){
        $data = $this->_contractService->getInvoicesAbstract();
        $this->exportJson($data, $this->_contractService->getErrCode(), $this->_contractService->getErrMsg());
    }

    /**
     * 出库信息
     */
    public function actionGetOrganizationInfo()
    {
        $beginTime = $this->getParamData('beginTime');
        $endTime = $this->getParamData('endTime');

        $data = $this->_contractService->getGetOrganizationInfoByTime($beginTime, $endTime);
        $this->exportJson($data, $this->_contractService->getErrCode(), $this->_contractService->getErrMsg());
    }

    /**
     * 款项发票回款关联表
     */
    public function actionGetInvoicePayment()
    {
        $contractid = $this->getParamData('contractid');
//        $beginTime = $this->getParamData('beginTime');
//        $endTime = $this->getParamData('endTime');
        $data = $this->_contractService->getInvoicePaymentByTime('', '',$contractid);
        $this->exportJson($data, $this->_contractService->getErrCode(), $this->_contractService->getErrMsg());
    }

    /**
     * 应收款表
     */
    public function actionGetReceivableInfo()
    {
        $beginTime = $this->getParamData('beginTime');
        $endTime = $this->getParamData('endTime');
        $contractid = $this->getParamData('contractid');

        $data = $this->_contractService->getReceivableInfoByTime($contractid, $beginTime, $endTime);
        $this->exportJson($data, $this->_contractService->getErrCode(), $this->_contractService->getErrMsg());
    }

    /**
     * 收入数据接口
     */
    public function actionGetRevenueInfo()
    {
        $beginTime = $this->getParamData('beginTime');
        $endTime = $this->getParamData('endTime');

        $data = $this->_contractService->getRevenueInfotByTime($beginTime, $endTime);
        $data = $this->setContractBillPaymentAmount($data, 'contract_id');
        $data = $this->setContractRent($data, 'contract_id');
        $this->exportJson($data, $this->_contractService->getErrCode(), $this->_contractService->getErrMsg());
    }

    /**
     * 设置缓存
     */
    public function actionSetCache()
    {
        $key = $this->getParamData('key');
        $value = $this->getParamData('value');
        if (empty($key) || empty($value)) {
            die('no key or no value');
        }
        $time = $this->getParamData('time');
        $time = empty($time) ? 60 : $time;
        $ret = Yii::$app->cache->set($key, $value, $time);
        $this->exportJson('ok', $this->_contractService->getErrCode(), $this->_contractService->getErrMsg());
    }

    /**
     * 关闭缓存
     * @param type $key
     */
    public function actionGetCache()
    {
        $key = $this->getParamData('key');
        if (empty($key)) {
            die('no key');
        }
        $value = Yii::$app->cache->get($key);
        $this->exportJson($value, $this->_contractService->getErrCode(), $this->_contractService->getErrMsg());
    }

    /**
     * 报价单(即会签)归档后同步生效信息至终端合同系统,已审核
     */
    public function actionAddContractDraft()
    {
        // 合同
        $contractData = $this->getParamData('contract');
        $contract = json_decode($contractData, true);
        //默认合同性质
        //$contract['contract_property_id'] = '7f83719a-fce8-11e4-bed8-00155d02c832';
        //默认合同类别
        $contract['category_id'] = 'b011f523-fcf2-11e4-bed8-00155d02c832';//由于商机系统那边没有此字段，故默认为“云链租用服务合同”
        $contract['big_category_id'] = '2ae79470-fcf3-11e4-bed8-00155d02c832';//由于商机系统那边没有此字段，故默认为“服务合同”
        $contract['littler_category_id'] = '62f81bf4-fcf4-11e4-bed8-00155d02c832';//由于商机系统那边没有此字段，故默认为“软件租用服务”
        //$contract['company_id'] = '593d3902-006a-11e5-bed8-00155d02c832';//由于商机系统那边没有此字段，故默认为“明源云服务”
//        $contract['attribute_name'] = 'true,false,false';//由于商机系统那边没有此字段，故默认为“新增”

        /** @var ErpInterfaceService $erpInterfaceService */
        $erpInterfaceService = Yii::createObject(ErpInterfaceService::className());
        $signUserData = $erpInterfaceService->getUserInfoById($contract['sign_people_id']);
        $contract['area_id'] = $signUserData['BUGUID'];
        $contract['area_name'] = $signUserData['CompanyName'];
        $contract['area_code'] = $signUserData['BUCode'];
        $contract['sign_people_department_by'] = $signUserData['DepartmentGUID'];
        $contract['sign_people_department_name'] = $signUserData['DepartmentName'];

        // 应收款
        $receivableData = $this->getParamData('receivable');
        if ($receivableData) {
            $receivable = json_decode($receivableData, true);
        } else {
            $receivable = [];
        }

        //产品信息
        $productinfosData = $this->getParamData('productinfo');
        if($productinfosData){
            $productinfos = json_decode($productinfosData,true);
        }else{
            $productinfos = [];
        }

        //收入信息
        $incomeinfosData = $this->getParamData('incomeinfo');
        if($productinfosData){
            $incomeinfos = json_decode($incomeinfosData,true);
        }else{
            $incomeinfos = [];
        }

        //文档信息
        $docinfosData = $this->getParamData('docinfo');
        if($docinfosData){
            $docinfos = json_decode($docinfosData,true);
        }else{
            $docinfos = [];
        }

        $result = $this->_contractService->doInsertFromBusinessSystem($contract, $receivable,$productinfos,$incomeinfos,$docinfos);
        $this->exportJson($result, $this->_contractService->getErrCode(), $this->_contractService->getErrMsg());
    }

    /**
     * [直属]终端erp混签合同,三云公司录入进货合同,草稿,支持变更
     */
    public function actionAddContractEkpDraft(){
        $contractData = $this->getParamData('contract');
        $contract = json_decode($contractData, true);
        if(empty($contract)){
            $this->errorParam();
        }

        $productData = json_decode($this->getParamData('productinfo'));
        $docData = json_decode($this->getParamData('docinfo'));

        $result = $this->_contractService->saveContractDraft($contract,$productData,$docData);
        $this->exportJson($result, $this->_contractService->getErrCode(), $this->_contractService->getErrMsg());
    }

    /**
     * [联营,与直属合同是两个系统]终端erp混签合同,三云公司录入进货合同,草稿
     */
    public function actionAddLinkContractDraft(){
        $contractData = $this->getParamData('contract');
        $contract = json_decode($contractData, true);
        if(empty($contract)){
            $this->errorParam();
        }

        $productData = json_decode($this->getParamData('productinfo'));
        $docData = json_decode($this->getParamData('docinfo'));

        $result = $this->_contractService->saveLinkContractDraft($contract,$productData,$docData);
        $this->exportJson($result, $this->_contractService->getErrCode(), $this->_contractService->getErrMsg());
    }

    /**
     * 新增发票(1、新增发票不指定合同， 2、新增发票关联合同应收款项)
     * @param invoice  json
     */
    public function actionSaveInvoice(){
        $invoiceJson = $_REQUEST["invoice"];
        $invoice = json_decode($invoiceJson, true);
        $invoiceModel = new InvoiceModel(['scenario' => 'saveinvoice']);
        if($invoiceModel->load($invoice, '')){
            if(empty($invoiceModel->contract_id)){
                $result = $this->_invoiceService->saveInvoice($invoiceModel);
                $this->exportJson($result, $this->_invoiceService->getErrCode(), $this->_invoiceService->getErrMsg());
            }
            else{
                //判断合同下同一应收款是否有相同金额的收据,如果有则先删除收据,然后保存推过来的发票,刷新现有数据
                $invoiceinfo =  InvoiceRepository::getInvoiceByIdAndReceivable($invoiceModel);
                if(!empty($invoiceinfo)){
                    //新过来的发票没有发票id,将其直接替换为被替换收据的ID,后面按照更新逻辑处理流程
                    if(empty($invoiceModel->invoice_id)){
                        $invoiceModel->invoice_id = $invoiceinfo[0]['invoice_id'];
                    }
                };

                $this->CalcBillingAmount($invoiceModel);
                $result = $this->_receivableService->saveInvoiceReceivable($invoiceModel);
                $this->exportJson($result, $this->_receivableService->getErrCode(), $this->_receivableService->getErrMsg());
            }
        }
        else{
            $this->errorParam();
        }
    }

    /**
     * 开票金额 分到 具体的应收款项里
     * @param $invoiceModel
     * @return mixed
     */
    private function CalcBillingAmount(&$invoiceModel)
    {
        $invoiceReceivables = $invoiceModel->invoiceReceivables;
        //已分配的金额
        $billingAmount = 0;
        if (isset($invoiceReceivables) && count($invoiceReceivables) > 0) {
            //合同的应收金额、已开票金额明细
            $receivables = $this->_receivableService->getReceivableInfoByContractId($invoiceModel->contract_id, false);
            foreach ($invoiceModel->invoiceReceivables as $k => &$v) {
                foreach ($receivables as $r) {
                    if ($r['receivable_id'] == $v['receivable_id']) {
                        //此应收款可关联的开票金额
                        $leaveAmount = $r['receivable_amount'] - $r['billing_amount'];
                        $v['cur_billing_amount'] = ($invoiceModel->invoice_amount - $billingAmount) >= $leaveAmount ?
                            $leaveAmount : ($invoiceModel->invoice_amount - $billingAmount);
                        $billingAmount += $v['cur_billing_amount'];
                    }
                }
            }
        }
    }

    /**
     *为了方便测试接口,模拟返回数据以便调试
     * @return array
     */
    public function actionReturnModelData(){
        $result = (object)null;
        $result->errorCode = 0;
        $result->success = true;
        $result->message = '';
        $result->data = [
            'company_name' => '测试公司',
            'investigation_time' => '2017-07-22 23:12:29',
            'expiration_time' => '2017-07-22 23:12:29',
            'file_id' => '592847088340005e9512a7e4'
        ];
        return json_encode($result);
    }

    /**
     *取云链直销合同的签约业绩合同明细数据
     */
    public function actionGetDirectContract(){
        $beginTime = $this->getParamData('beginTime');
        $endTime = $this->getParamData('endTime');

        $list = $this->_contractService->getDirectContract($beginTime,$endTime);

        $this->exportJson($list, $this->_contractService->getErrCode(), $this->_contractService->getErrMsg());
    }

    /**
     * 取云链直销合同的回款业绩明细数据
     */
    public function actionGetDirectContractPayment(){
        $beginTime = $this->getParamData('beginTime');
        $endTime = $this->getParamData('endTime');

        $list = $this->_contractService->getDirectContractPayment($beginTime,$endTime);

        $this->exportJson($list, $this->_contractService->getErrCode(), $this->_contractService->getErrMsg());
    }

    /**
     * 多租户取用户信息
     */
    public function actionGetErpUserInfo(){
        $name = $this->getParamData('keyword');
        if(empty($name)){
            $data = [];
        }else{
            $data = ContractManageRepository::getErpUserInfoByName($name);
        }
        $this->exportJson($data, $this->_contractService->getErrCode(), $this->_contractService->getErrMsg());
    }

    public function actionGetOrderInfo(){
        $contractguid = $this->getParamData('ContractGuid');
        $beginTime = $this->getParamData('beginTime');
        $endTime = $this->getParamData('endTime');
//        $data = ContractManageRepository::getContractOrderInfo($contractguid);
        $data = $this->_contractService->getOrdersInfo($contractguid,$beginTime,$endTime);
        $this->exportJson($data, $this->_contractService->getErrCode(), $this->_contractService->getErrMsg());
    }


    /**
     * 标的物同步至合同系统接口
     */
    public function actionAddDocumentInfo(){
        $docs = $this->getDocumentParams();
        $result = $this->_contractService->doSyncDocument($docs);
        $this->exportJson($result, $this->_contractService->getErrCode(), $this->_contractService->getErrMsg());
    }


    /**
     * 标的物同步至合同系统接口数据格式化
     * @return array
     */
    private function getDocumentParams(){
        $filesData = $this->getParamData('FileList');
        $filesList = json_decode($filesData,true);
        $collections = array();
        foreach ($filesList as $files){
            $document = array();
            $document['document_id'] = $files['FileGUID'];
            $document['document_name'] = $files['FileName'];
            $document['document_ext_name'] = '标的物';
            $document['document_path'] = $files['NetWorkUrl'];
            $document['business_id'] = $files['ContractGUID'];
            $document['created_by'] = $files['CreatorName'];
            $document['created_on'] = $files['CreateTime'];
            $document['out_file_id'] = $files['OutFileID'];
            $document['creator_id'] = $files['CreatorGUID'];
            $document['recipient_id'] = $files['ReceiveUserGUID'];
            $document['received_by'] = $files['ReceiveUser'];
            $document['received_on'] = $files['ReceiveDate'];
            $document['is_sign'] = $files['IsSignName'].'';
            $document['contract_code'] = $files['ContractCode'];
            $document['document_old_name'] = $files['FileOldName'];
            $document['document_new_name'] = $files['FileNewName'];
            $document['opportunities_id'] = $files['OpportunitiesGUID'];
            $document['document_size'] = $files['FileSize'];
            $document['document_group'] = $files['FileGroup'];
            $document['bop_file_type'] = $files['BopFileType'];
            $collections[] = $document;
        }
        return $collections;
    }

    /**
     * 特批授权接口
     */
    public function actionGetSpecialApprovalAuthorizeList(){
        $pageIndex = \Yii::$app->request->post('pageIndex',0);
        $pageSize =  \Yii::$app->request->post('pageSize',0);
        $sortBy = 'actual_fulfil_time';
        $sortAsc = '';
        $keyword = \Yii::$app->request->post('keyword','');
        $areaId = \Yii::$app->request->post('areaId','');
        $fulfil = \Yii::$app->request->post('fulfil','');
        $result = $this->_authorizeService->getSpecialApprovalAuthorizeList($pageIndex, $pageSize, $sortBy, $sortAsc, $keyword, $areaId, $fulfil);
        $special_type = array(1=>'合同未归档',2=>'首期款未回',3=>'授权信息与合同信息不一致',4=>'合同扫描件未提供',5=>'结算款未支付',6=>'其他',7=>'合同未归档,首期款未回');
        foreach ($result['items']  as $key => $item){
            $data = array();
            $data['rentname'] = $item['organization_name'];
            $data['contractcode'] = $item['contract_code'];
            $data['rentstartdate'] = $item[''];
            $data['rentenddate'] = $item[''];
            $data['specialtype'] = $special_type[$item['category']];
            $data['cashpersonguid'] = $item['promise_fulfil_principle'];
            $data['cashperson'] = $item['principal_name'];
            $data['promisedate'] = $item['promise_fulfil_time'];
            $data['cashdate'] = $item['actual_fulfil_time'];
            $data['createdon'] = $item['created_on'];
            $data['createdby'] = $item['created_by'];
            $data['modifiedon'] = $item['modified_on'];
            $data['modifiedby'] = $item['modified_by'];
            $result['items'][$key] = $data;
        }
        $this->exportJson($result, $this->_authorizeService->getErrCode(), $this->_authorizeService->getErrMsg());
    }
}
